package com.ruoyi.web.controller.app.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.exception.base.XException;
import com.ruoyi.sj.domain.DynamicPermit;
import com.ruoyi.sj.mapper.DynamicPermitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @ClassName AppDynamicPermitService
 * @Description TODO
 * @Author tyc@yanyu
 * @Date 2018/12/29 0029 17:52
 **/
@Service
public class AppDynamicPermitService {
    @Autowired
    private DynamicPermitMapper dynamicPermitMapper;

    /**
     * 增加朋友圈权限
     *
     * @param
     * @return
     */
    public int insertDynamicPermit(String dynamicId, String businessId) {
        if (StringUtils.isBlank(dynamicId)){
            throw new XException("动态id不能为空！");
        }
        int i=0;
        if (businessId != null && !businessId.equals("")) {
            String[] businessIds = businessId.split(",");
            DynamicPermit dynamicPermit = new DynamicPermit();
            for (String business : businessIds) {
                dynamicPermit.setBusinessId(Long.valueOf(business));
                dynamicPermit.setDynamicId(Long.valueOf(dynamicId));
                i=dynamicPermitMapper.insertDynamicPermit(dynamicPermit);
            }
            return i;
        } else {
            return 0;
        }
    }


}
